<?php

use Illuminate\Support\Facades\Route;
use App\Services\CodeService;


//首页
//
Route::get('/', 'HomeController@entry')->name('home')->middleware(['front']);
//账号登录
Route::group(['namespace' => 'Account', 'middleware' => ['front']], function () {
    Route::resource('login', 'LoginController')->only(['index', 'store'])->names(['index' => 'login']);
    Route::get('logout', 'LoginController@logout')->name('logout');
    //账号注册
    Route::resource('register', 'RegisterController')->only(['index', 'store'])->names(['index' => 'register']);

    Route::resource('forgetpassword', 'ForgetPasswordController')->only(['create', 'store']);

    //关注粉丝
    Route::get('follower/{user}', 'UserController@follower')->name('user.follower');
});

//后台管理员
Route::get('admin', 'Site\SiteController@index')->name('admin')->middleware(['auth', 'system']);

Route::group(['prefix' => 'admin', 'namespace' => 'Admin', 'as' => 'admin.', 'middleware' => ['auth', 'system']], function () {
    Route::view('system', 'system.setting')->name('setting');
    //name admin.module.index
    //模块列表 安装 卸载
    Route::get('module', 'ModuleController@index')->name('module.index');
    Route::get('module/install/{name}', 'ModuleController@install')->name('module.install');
    Route::delete('module/uninstall/{module:name}', 'ModuleController@uninstall')->name('module.uninstall');

    Route::resource('package', 'PackageController');
    Route::resource('group', 'GroupController');

    Route::get('config', 'ConfigController@edit')->name('config.edit');
    Route::put('config', 'ConfigController@update')->name('config.update');
    Route::post('upload', 'ConfigController@upload')->name('config.upload');

    Route::get('my', 'MyController@edit')->name('my.edit');
    Route::put('my', 'MyController@update')->name('my.update');


});

//站点管理
Route::group(['prefix' => 'site', 'namespace' => 'Site', 'as' => 'site.', 'middleware' => ['auth', 'system']], function () {
    Route::resource('site', 'SiteController');
//路由先后顺序的问题,匹配成功后就会不继续向下匹配，所以，注意resource的其他方法是否有覆盖问题
    Route::post('{site}/admin/search', 'AdminController@search')->name('admin.search');
    Route::get('{site}/admin/add/{user}', 'AdminController@add')->name('admin.add');
    Route::resource('{site}/admin', 'AdminController');

    Route::get('{site}/admin/role/{user}', 'AdminController@role')->name('admin.role');
    Route::put('{site}/admin/role/{user}', 'AdminController@roleUpdate')->name('admin.roleUpdate');

    Route::resource('{site}/role', 'RoleController');

    Route::get('{site}/permission/{role}', 'PermissionController@edit')->name('permission.edit');
    Route::put('{site}/permission/{role}', 'PermissionController@update')->name('permission.update');

    Route::get('{site}/module', 'ModuleController@index')->name('module.index');
    Route::get('{site}/module/{module}', 'ModuleController@entry')->name('module.entry');
//网站配置
    Route::get('{site}/config', 'ConfigController@edit')->name('config.edit');
    Route::put('{site}/config', 'ConfigController@update')->name('config.update');


//网站配置结束
});

Route::group(['prefix' => 'common', 'namespace' => 'Common', 'as' => 'common.', 'middleware' => ['auth']], function () {

    Route::post('upload', 'UploadController@make')->name('upload');


});
//公共功能
Route::group(['prefix' => 'common', 'namespace' => 'Common', 'as' => 'common.'], function () {

    //一分钟一次throttle:1,1 验证码
    Route::post('code', 'CodeController@code')->name('code')->middleware(['throttle:10,1', 'front']);

    Route::any('{model}/{id}/favorite', 'FavoriteController@make')->name('favorite');
    Route::any('{model}/{id}/favour', 'FavourController@make')->name('favour');

    Route::post('live/push', 'LiveController@push')->name('live.push')->middleware('auth');
    Route::any('live.notify', 'LiveController@notify')->name('live.notify')->middleware('auth');
    //根据路由名返回路由url地址
    Route::get('route', 'RouteController@make')->name('route');

    Route::get('pay/alipaySync/{module}', 'PayController@alipaySync')->name('alipay.sync');
    Route::post('pay/alipayAsync/{module}', 'PayController@alipayAsync')->name('alipay.async');

    Route::post('pay/wepayAsync/{module}', 'PayController@wepayAsync')->name('wepay.async');


});
//平台个人中心
Route::group(['prefix' => 'member', 'middleware' => ['auth', 'front'], 'namespace' => 'Member', 'as' => 'member.'], function () {
    Route::resource('base', 'BaseController')->only(['create', 'store']);
    Route::resource('avatar', 'AvatarController')->only(['create', 'store']);
    Route::post('upload', 'AvatarController@upload')->name('avatar.upload');
    Route::resource('password', 'PasswordController')->only(['create', 'store']);
    Route::resource('email', 'MailController')->only((['create', 'store']));
    Route::resource('wechat', 'WechatController')->only(['creat', 'store']);
    Route::resource('mobile', 'MobileController')->only(['create', 'store']);
    Route::post('mobile/code', 'MobileController@code')->name('mobile.code')->middleware(['throttle:5,1']);


});
//直播
Route::group(['prefix' => 'LiveAdmin', 'namespace' => 'LiveAdmin', 'as' => 'liveAdmin.', 'middleware' => ['auth', 'front']], function () {
    Route::post('speek', 'LiveAdminController@speek')->name('speek');
    Route::post('kickout', 'LiveAdminController@kickout')->name('kickout');
    Route::post('index', 'LiveAdminController@index')->name('index');
    Route::post('search', 'LiveAdminController@search')->name('search');
});

//模块配置
Route::group(['prefix' => 'module', 'namespace' => 'Module', 'as' => 'module.', 'middleware' => ['auth', 'admin']], function () {
    Route::get('config', 'ConfigController@edit')->name('config.edit');
    Route::put('config', 'ConfigController@update')->name('config.update');
});
//微信//微信接口
Route::any('houdunren/wechat/{model}', 'WxApi\ApiController@handle')->middleware('front');
//单独配置站点微信公众号
Route::group(['prefix' => 'site/wechat/{site}', 'namespace' => 'WeChat', 'as' => 'wechat.', 'middlware' => ['auth']], function () {
    Route::resource('wechat', 'WeChatController');
    Route::get('wechat/default/{wechat}', 'DefaultController@edit')->name('wechat.default.edit');
    Route::put('wechat/default/{wechat}', 'DefaultController@update')->name('wechat.default.update');
    Route::get('wechat/menu/{wechat}/edit', 'MenuController@edit')->name('wechat.menu.edit');
    Route::put('wechat/menu/{wechat}', 'MenuController@update')->name('wechat.menu.update');
    Route::get('wechat/menu/{wechat}', 'MenuController@show')->name('wechat.menu.show');
    Route::get('wechat/menu/push/{wechat}', 'MenuController@push')->name('wechat.menu.push');
});


//微信管理
Route::group(['prefix' => 'wechat', 'namespace' => 'WeChat', 'as' => 'wechat.', 'middleware' => ['auth', 'admin']], function () {
    Route::get('rule/wechat', 'RuleController@wechat')->name('rule.wechat');
    Route::resource('text', 'TextController');
    Route::resource('rule', 'RuleController')->only('show', 'destroy');
    Route::resource('news', 'NewsController');
    Route::resource('material', 'MaterialController');
    Route::post('keyword/check', 'KeywordController@check')->name('keyword.check');
});


